﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;

public class EditorCommon 
{
    /// <summary>
    /// Clear console content
    /// </summary>
    public static void ClearConsole()
    {
        var logEntries = System.Type.GetType("UnityEditorInternal.LogEntries,UnityEditor.dll");
        var clearMethod = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
        clearMethod.Invoke(null, null);
    }

    /// <summary>
    /// Replace "\\" with "/"
    /// </summary>
    public static string ReplaceSlash(string s)
    {
        return s.Replace("\\", "/");
    }

    /// <summary>
    /// Check the directory ,and create the directory if the directory does not exist
    /// </summary>
    /// <param name="directory"></param>
    public static void CheckOrCreateDirectory(string directory)
    {
        if (!System.IO.Directory.Exists(directory))
            System.IO.Directory.CreateDirectory(directory);
    }

    /// <summary>
    /// Get all the files in the directory specified path information, with a filter
    /// </summary>
    /// <param name="strPath"></param>
    /// <param name="lstFiles"></param>
    /// <param name="lstFilters"></param>
    public static void GetAllFiles(string strPath,ref List<FileInfo> lstFiles,List<string> lstFilters)
    {
        DirectoryInfo folder = new DirectoryInfo(strPath);
        FileSystemInfo[] files = folder.GetFileSystemInfos();

        foreach (var item in files)
        {
            if (item is DirectoryInfo)
                GetAllFiles(item.FullName, ref lstFiles, lstFilters);
            else
            {
                bool needAdd = true;
                for (int k = 0; k < lstFilters.Count; k++)
                {
                    if (item.Name.EndsWith(lstFilters[k], StringComparison.OrdinalIgnoreCase))
                    {
                        needAdd = false;
                        break;
                    }
                }
                if (needAdd)
                    lstFiles.Add(item as FileInfo);
            }
        }
    }

    /// <summary>
    /// Determine whether the path exists
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static bool IsExists(string path)
    {
        return Directory.Exists(path);
    }

    public static void CopyFile(string strSrcDic, string strDesDir, List<string> lstFilter, Utility.FileUtils.CopyFileCallback callback)
    {
        List<string> lstFiles = new List<string>();
        Utility.FileUtils.Instance().CopyDirectory(strSrcDic, strDesDir, ref lstFiles, lstFilter, callback);
    }

}
